package ar.com.ford.it.fullEconomics.interfaces;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Collection;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp01Part;
import cobolConversion.EbcdicString;
import cobolConversion.EbcdicTable;
import cobolConversion.PackedDecimal;

public class ReadFileIntoByteArray {
	private EbcdicTable ebcdicTable = new EbcdicTable();

	/**
	 * Sole entry point to the class and application.
	 * 
	 * @param args
	 *            Array of String arguments.
	 */
	public static void main(String[] args) {

		BufferedInputStream myMvsFile = null;
		try {
			myMvsFile = new BufferedInputStream(new FileInputStream(
					"C:\\Temp\\argprice.txt"));

			File arch = new File("C:\\Temp\\argprice.txt");

			byte myBufferReadHeader[] = new byte[650];
			byte preciodePieza[] = new byte[7];
			// Interpretador de datos cobol
			EbcdicTable ebcdicTable = new EbcdicTable();
			ebcdicTable.set_pageCode(EbcdicTable.ASCII_USA_00437);

			myMvsFile.read(myBufferReadHeader, 0, 650);
			System.out
					.println(new EbcdicString(ebcdicTable, myBufferReadHeader)
							.toString().toString());
			Teesp01Part part = null;
			Collection<String> plantas = new ArrayList();
			myMvsFile.read(myBufferReadHeader, 0, 650);
			for (long i = 0; i < 30; i++) {
				// Datos Irrelevantes

				myMvsFile.read(myBufferReadHeader, 0, 650);
				// Leo la linea
				String line = new EbcdicString(ebcdicTable, myBufferReadHeader)
						.toString().toString();
				System.out.println(line);
				System.out.println(line.toString().substring(51,73));
				if (true) {
					preciodePieza[0]= myBufferReadHeader[154];
					preciodePieza[1]= myBufferReadHeader[155];
					preciodePieza[2]= myBufferReadHeader[156];
					preciodePieza[3]= myBufferReadHeader[157];
					preciodePieza[4]= myBufferReadHeader[158];
					preciodePieza[5]= myBufferReadHeader[159];
					preciodePieza[6]= myBufferReadHeader[160];
					System.out.println(preciodePieza.length);
					String line2 = new EbcdicString(ebcdicTable, preciodePieza)
					.toString().toString();
					PackedDecimal decimal = null;
					decimal = new PackedDecimal(preciodePieza,0,0,0);
					
			System.out.println(decimal.toString());
				}
			}
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
	}

	private static boolean isReadPart(byte[] bufferLecture) {
		EbcdicTable ebcdicTable = new EbcdicTable();
		ebcdicTable.set_pageCode(EbcdicTable.ASCII_USA_00437);
		EbcdicString ebcdicString = new EbcdicString(ebcdicTable, bufferLecture);
		if (ebcdicString.toString().trim().substring(12).equals("1")) {
			return true;
		}

		return false;
	}

	private static boolean isTrailer(byte[] bufferLecture) {
		// EbcdicTable ebcdicTable = new EbcdicTable();
		// ebcdicTable.set_pageCode(EbcdicTable.ASCII_USA_00437);
		// EbcdicString ebcdicString = new EbcdicString(ebcdicTable,
		// bufferLecture);
		// if (ebcdicString.toString().equals("A")) {
		return true;
		// }
		// return false;
	}


}
